package cn.edu.scnu.thewonderofink.ui.dictionary

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.edu.scnu.thewonderofink.R
import cn.edu.scnu.thewonderofink.databinding.FragmentDictionaryBinding
import cn.edu.scnu.thewonderofink.ui.home.HorizontalSpacingDecoration

class DictionaryFragment : Fragment() {
    val viewModel by lazy { ViewModelProvider(this).get(DictionaryViewModel::class.java) }

    private var _binding: FragmentDictionaryBinding? = null
      // This property is only valid between onCreateView and
      // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val dashboardViewModel =
            ViewModelProvider(this).get(DictionaryViewModel::class.java)

        _binding = FragmentDictionaryBinding.inflate(inflater, container, false)

        return binding.root
    }

    @Deprecated("Deprecated in Java")
    @SuppressLint("NotifyDataSetChanged")
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

//        // 以下为recycleView的使用代码
//        val recyclerView : RecyclerView = binding.recyclerView
//        val layoutManager = LinearLayoutManager(context)
//        recyclerView.layoutManager = layoutManager
//        val imageList = ArrayList<Int>()
//        imageList.add(R.drawable.dictionary_not_selected)
//        imageList.add(R.drawable.ic_home)
//        imageList.add(R.drawable.ic_dictionary)
//        viewModel.setImageLiveData(imageList)
//        recyclerView.visibility =  View.VISIBLE
//
//        viewModel.imageLiveData.observe(viewLifecycleOwner){
//            val adapter = RecyclerViewAdapter(it)
//            recyclerView.adapter = adapter
//            adapter.notifyDataSetChanged()
//        }
        // 到此处结束
    }

    override fun onDestroyView() {
            super.onDestroyView()
            _binding = null
    }
}